<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */

/**
 * Form for adding events
 *
 * @category    RedCross
 * @package     Admin_Form_Shift
 */
class Admin_Form_Shift_Create extends RedCross_Form
{

    public function init()
    {
        $this->addElement('text', 'name', array(
            'filters' => array('StringTrim'),
            'required' => true,
            'label' => 'Navn på vakten'
        ));

        $this->addElement('text', 'from_date', array(
			'validators' => array('Date'),
            'required' => true,
			'label' => 'Startdato:'
	    ));

        $this->addElement('time', 'from_time', array(
			'validators'	=> array(
				array('Time',true,array('name' => 'from_time')),
			),
            'required'	=> true,
			'label' => 'Starttidspunkt:'
		));

        $this->addElement('text', 'to_date', array(
            'validators' => array('Date'),
            'required' => true,
            'label' => 'Sluttdato:'
        ));

	    $this->addElement('time', 'to_time', array(
			'validators' => array(
				array('Time', true, array('name' => 'to_time')),
			),
            'required' => true,
			'label' => 'Sluttidspunkt:'
		));

        $this->addElement('select', 'shift_template', array(
            'label' => 'Vaktmal: (valgfritt)'
        ));

        $this->addElement('submit', 'submit', array(
            'required' => true,
            'label' => 'Lag vakt'
        ));

        $this->fillFormValues();
    }


    private function fillFormValues()
    {
        $shiftTemplateService = RedCross_Factory::getService('Core_Service_ShiftTemplate');
        $templates = $shiftTemplateService->fetchAllWithOnlyIdAndName();

        $templateElement = $this->getElement('shift_template');
        $templateElement->addMultiOption(null, '-- Velg vaktmal --');

        foreach($templates as $t) {
            $templateElement->addMultiOption($t['id'], $t['name']);
        }
    }
}
